# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html

import pymysql

class SalarysPipeline(object):

    def __init__(self):
        self.client = pymysql.connect(
            host='localhost',
            port=3306,
            user='root',    #使用自己的用户名   
            passwd='shusheng',  # 使用自己的密码  
            db='self',       # 数据库名  
            charset='utf8'
        )
        self.cur = self.client.cursor()

    def process_item(self, item, spider):
        sql = "insert into works(local,job,cname,min_salary,max_salary,exp,origin,publish_time) values(%s,%s,%s,%s,%s,%s,%s,%s)"
        param = (item['local'],item['job'],item['cname'],item['min_salary'],item['max_salary'],item['exp'],item['origin'],item['publish_time'])
        self.cur.execute(sql,param)
        self.client.commit()
        return item

